<template>
	<view class="box">
		<view class="top-nav">
			<u-tabs :list="listTabs" @change="hdtab" lineWidth="51rpx" lineHeight="9rpx" lineColor="#fb8b06"
				:inactiveStyle="{fontSize:'28rpx',color:'#777777'}" :activeStyle="{fontSize:'28rpx',color:'#2E2E2E'}"></u-tabs>
		</view>

		<view class="li" v-for="item in userVoucher_list" :key="item.id">
			<view class="top">
				<view class="l">
					单用券
				</view>
				<view class="r oneline-hide">
					{{item.content}}
				</view>
			</view>
			<view class="name">
				{{item.title}}
			</view>
			<view class="c">
				<view class="pric">
					<view class="l">
						￥
					</view>
					<view class="p">
						{{item.arrive_price}}
					</view>
				</view>
				<template v-if="item.is_use == 0">
					<view class="right" @click="toShopping">
						立即使用
					</view>
				</template>
				<template v-else>
					<view v-if="item.is_use == 1" class="right" style="background: darkgray;">
						已使用
					</view>
					<view v-else class="right" style="background: darkgray;">
						已过期
					</view>
				</template>
			</view>
			<view class="manjian">
				<view class="price">
					满{{item.threshold_price}}元可用
				</view>
				<view class="date">
					{{item.end_time}}到期
				</view>
			</view>
		</view>

		<view class="btn" @click="$navTo('pages/mines/couponDetails')">
			领券中心
		</view>
	</view>
</template>

<script>
	import {
		UserApi
	} from '@/api';
	export default {
		data() {
			return {
				listTabs: [{
						name: '全部',
						id: -1
					}, {
						name: '未使用',
						id: 0
					},
					{
						name: '已使用',
						id: 1
					}, {
						name: '已失效',
						id: 2
					}
				],
				userVoucher_list: [],
				useStatus: -1,
				p: 1
			};
		},
		onLoad() {
			this.couponList()
		},
		onReachBottom() {
			this.p += 1
			this.couponList(false)
		},
		methods: {
			async couponList(bol = true) {
				try {
					if (bol) this.p = 1
					const res = await UserApi.userVoucher({
						useStatus: this.useStatus,
						p: this.p
					})
					if (bol)
						return this.userVoucher_list = res.result
					this.userVoucher_list.push(...res.result)

				} catch (e) {
					//TODO handle the exception
				}
			},
			hdtab(e) {
				this.useStatus = e.id
				this.couponList()
			},
			toShopping() {
				uni.switchTab({
					url: '/pages/study/index'
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.box {
		width: 100vw;
		box-sizing: border-box;
		padding: 30rpx;
		padding-bottom: 200rpx;

		.btn {
			position: fixed;
			bottom: calc(30rpx + constant(safe-area-inset-bottom));
			bottom: calc(30rpx + env(safe-area-inset-bottom));
			left: 30rpx;
			width: 690rpx;
			height: 88rpx;
			border-radius: 50rpx;
			opacity: 1;
			background: linear-gradient(173.2deg, #f8b280 0%, #ff8b38 100%);
			text-align: center;
			line-height: 88rpx;
			color: #fff;
			font-size: 30rpx;
		}

		.top-nav {
			border-bottom: 1rpx solid #eaeaea;
		}

		.li {
			margin-bottom: 30rpx;
			width: 690rpx;
			height: 288rpx;
			padding: 25rpx;
			border-radius: 19rpx;
			opacity: 1;
			box-sizing: border-box;
			background: #ffffff;
			border-bottom: 1rpx solid #eaeaea;

			.manjian {
				display: flex;
				align-items: center;
				justify-content: space-between;

				.date {
					color: #999999;
					text-align: left;
					font-size: 28rpx;
					font-weight: 400;
				}

				.price {
					color: #000000;
					text-align: left;
					font-size: 28rpx;
					font-weight: 400;
				}
			}


			.c {
				display: flex;
				align-items: center;
				justify-content: space-between;
				width: 100%;

				.right {
					width: 188rpx;
					height: 64rpx;
					border-radius: 32rpx;
					line-height: 64rpx;
					opacity: 1;
					background: #fb8b07;
					color: #ffffff;
					text-align: center;
					font-size: 32rpx;
					font-weight: 400;
				}

				.pric {
					display: flex;
					align-items: center;

					.l {

						opacity: 1;
						color: #fb8b07;
						font-size: 36rpx;
						font-weight: 400;
						font-family: "Source Han Sans";
					}

					.p {
						margin-left: 7rpx;
						opacity: 1;
						color: #fb8b07;
						font-size: 70rpx;
						font-weight: 400;
						font-family: "Source Han Sans";
					}
				}
			}

			.name {
				color: #000000;
				text-align: left;
				font-size: 32rpx;
				font-weight: 400;
			}

			.top {
				display: flex;
				align-items: center;
				margin-bottom: 17rpx;

				.r {
					color: #292929;
					text-align: left;
					font-size: 28rpx;
					font-weight: 400;
					margin-left: 10rpx;
				}

				.l {
					width: 112rpx;
					height: 40rpx;
					line-height: 40rpx;
					background: #ffeedb;
					color: #fb8b07;
					text-align: center;
					font-size: 24rpx;
					font-weight: 400;
				}
			}
		}
	}
</style>